package com.baizhi.service.impl;

import com.baizhi.dao.PatientDao;
import com.baizhi.entity.Patient;
import com.baizhi.service.PatientService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class PatientServiceImpl implements PatientService {
    @Autowired
    private PatientDao patientDao;
    @Override
    public void insertPatient(Patient p) {
        patientDao.insertPatient(p);
    }

    @Override
    public void deletePatient(Integer pid) {
        patientDao.deletePatient(pid);
    }

    @Override
    @Transactional(readOnly = true)
    public Patient selectById(Integer pid) {
        return patientDao.selectById(pid);
    }

    @Override
    public void updatePatient(Patient p) {
        patientDao.updatePatient(p);
    }

    @Override
    @Transactional(readOnly = true)
    public PageInfo<Patient> selectByPage(String name, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        PageInfo<Patient> pageInfo = new PageInfo<>(patientDao.selectAll(name));
        return pageInfo;
    }
}
